package com.star.controller;


import com.star.domain.Order;
import com.star.dto.ResponseData;
import com.star.service.OrderService;
import com.star.util.InspectionTokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Star
 * @since 2021-04-21
 */
@Controller
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 跳转 欲购买 订单页面
     * 判断 token 是否登录了
     *
     * @param order
     * @return
     */
    @RequestMapping("/shopOrder/{logId}/{orderName}")
    private String shopOrder(Order order, String token) {
        System.out.println("a" + token);
        System.out.println(order);

        //查看返回值是否匹配
        ResponseData inspection = InspectionTokenUtils.inspectionForm(token);
        //判断是否是否有token 证明已经登录了
        if (inspection.getCode() == ResponseData.ok().getCode() && order.getLogId() != -10) {
            //进行插入 订单表
            ResponseData responseData = orderService.orderAdd(order);
            //有token 证明已经登录 进行数据返回
            return "holdUp/order/orderinfoPay";
        } else {
            //没有登录 跳转登录页面
            return "public/my/mylogin";
        }
    }

    @RequestMapping("/shopPay")
    private String shopOrder() {
        return "holdUp/order/orderinfoPay";
    }
}

